<template>
  <div>
    <!-- 修改表单 -->
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="DialogFormVisibleCom" :close-on-click-modal="false"
               :close-on-press-escape="false">
      <el-form ref="amendForm" :model="formSubmitDataCom" :rules="rules" label-position="right" label-width="150px"
               style="width: 90%; margin:10px auto;">

        <el-row :gutter="20">
          <el-col :span="12">
            <!-- 生效日期 -->
            <el-form-item label="生效日期：" prop="broker_s_date" required>
              <el-date-picker
                v-model="formSubmitDataCom.broker_s_date"
                type="date"
                placeholder="Please pick a date"
                value-format="yyyy-MM-dd"
              />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <!-- 失效日期 -->
            <el-form-item label="失效日期：" prop="broker_e_date" required>
              <el-date-picker
                v-model="formSubmitDataCom.broker_e_date"
                type="date"
                placeholder="Please pick a date"
                value-format="yyyy-MM-dd"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="券商名称：" prop="broker_name" required>
              <el-input v-model="formSubmitDataCom.broker_name" placeholder="请输入劵商名称" disabled></el-input>
            </el-form-item>
          </el-col>
          <!-- 备注 -->
          <!-- <el-col :span="24">
            <el-form-item label="备注：" prop="remark">
              <el-input v-model="formSubmitDataCom.remark" placeholder="Please select" type="textarea"></el-input>
            </el-form-item>
          </el-col> -->
        </el-row>


      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button @click="resetFormData">
          重置
        </el-button>
        <el-button type="primary" @click="updateData()">
          提交
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// import PageHeaderLayout from '@/layouts/PageHeaderLayout'
// import ApeDrawer from '@/components/ApeDrawer'
// import { mapGetters } from 'vuex'
import XEUtils from 'xe-utils'
// 基础表格组件
import ExBaseTable from '@/components/VxeTable/ExBaseTable'
import resetFormSubmitData from '@/views/mixins/resetFormSubmitData'

export default {
  name: 'submitForm',
  mixins: [resetFormSubmitData],
  components: {
    ExBaseTable
  },
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false
    },
    dialogStatus: {
      type: String,
    },
    formSubmitData: {
      type: Object,
      default: function () {
        return {
          id: undefined,
          broker_s_date: '',
          broker_e_date: '',
          remark: '',
        }
      }
    },
  },
  // 定义属性
  data() {
    /* 生效日期校验 */
    var validateDateRangeSdate = (rule, value, callback) => {
      if (XEUtils.isEmpty(value)) {
        callback(new Error('生效日期必填!'));
      } else if ((!XEUtils.isEmpty(this.formSubmitDataCom.broker_e_date)) && (value > this.formSubmitDataCom.broker_e_date)) {
        callback(new Error('生效日期必须小于失效日期!'));
      } else {
        callback();
      }
    };
    /* 失效日期验证 */
    var validateDateRangeEdate = (rule, value, callback) => {
      if (XEUtils.isEmpty(value)) {
        callback(new Error('失效日期必填!'));
      } else if ((!XEUtils.isEmpty(this.formSubmitDataCom.broker_s_date)) && (value < this.formSubmitDataCom.broker_s_date)) {
        callback(new Error('失效日期必须大于生效日期!'));
      } else {
        callback();
      }
    };
    return {
      textMap: {
        update: '修改',
        create: '新增'
      },
      rules: {
        broker_s_date: [{validator: validateDateRangeSdate, trigger: 'change'}],
        broker_e_date: [{validator: validateDateRangeEdate, trigger: 'change'}],
        broker_name: [{required: true, message: '劵商名称必填', trigger: 'change'}],
      },
      /* 表格相关 */
      tableColumn: [], // 表格字段
      loading: false, //表格loading特效
      tableData: [],  //表格数据
      datalist: '',//选中的值
    }
  },
  // 计算属性，会监听依赖属性值随之变化
  computed: {
    DialogFormVisibleCom: {
      get() {
        return this.dialogFormVisible
      },
      set(val) {
        this.$emit('update:dialogFormVisible', val)
      }
    },
    formSubmitDataCom: {
      get() {
        return this.formSubmitData
      },
      set(val) {
        this.$emit('update:formSubmitData', val)
      }
    },
  },
  // 监控data中的数据变化
  watch: {},
  // 方法集合
  methods: {

    resetFormData() {
      let exclude = [
        'id',
        'broker_name'
      ]
      this.$emit('resetFormDataEmit', {exclude})
    },
    findlp() {
      this.$refs['datalp'].validate((valid) => {
        if (valid) {
          this.$emit('findlp')

        }
      })
    },
    updateData() {
      this.$refs['amendForm'].validate((valid) => {
        if (valid) {
          this.$delete(this.formSubmitDataCom, "_XID");
          this.$delete(this.formSubmitDataCom, "lp_name");
          const tempData = Object.assign({}, this.formSubmitData)
          this.$emit('handleFromUpdateDataEmit')

        }
      })
    },
  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {

  },
  beforeCreate() {
  }, // 生命周期 - 创建之前
  beforeMount() {
  }, // 生命周期 - 挂载之前
  beforeUpdate() {
  }, // 生命周期 - 更新之前
  updated() {
  }, // 生命周期 - 更新之后
  beforeDestroy() {
  }, // 生命周期 - 销毁之前
  destroyed() {
  }, // 生命周期 - 销毁完成
  activated() {
  }, // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>

<style lang='scss' scoped>

</style>
